import random

# 记录自己和对方的出拳历史
my_history = []
opponent_history = []

# 记录对手在你出不同拳时的应对策略
counter_stats = {
    "剪刀": {"剪刀": 0, "石头": 0, "布": 0},
    "石头": {"剪刀": 0, "石头": 0, "布": 0},
    "布": {"剪刀": 0, "石头": 0, "布": 0}
}

def lastmove(move):
    global opponent_history
    opponent_history.append(move)

    # 更新统计数据
    if my_history:
        counter_stats[my_history[-1]][move] += 1

def make_move():
    global my_history, opponent_history

    # 如果历史记录不足，随机出拳
    if len(opponent_history) < 3:
        choice = random.choice(["剪刀", "石头", "布"])
        my_history.append(choice)
        return choice

    # 针对历史依赖策略的优化
    if opponent_history[-1] == my_history[-2] and opponent_history[-2] == my_history[-3]:
        if opponent_history[-1] == "石头":
            choice = "布"
        elif opponent_history[-1] == "布":
            choice = "剪刀"
        else:
            choice = "石头"
        my_history.append(choice)
        return choice

    # 根据统计数据来预测对手的下一步
    predicted = max(counter_stats[my_history[-1]], key=counter_stats[my_history[-1]].get)
    if predicted == "石头":
        choice = "布"
    elif predicted == "布":
        choice = "剪刀"
    else:
        choice = "石头"

    my_history.append(choice)
    return choice

